﻿
layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = layui.layer;

    $(function () {
        loadList();
    });
});

//查询
function search() {
    var queryParams = {
        "s_0_NoticeTitle": $('#tbKey').val()
    };
    $.extend(true, _table.InitOptions.params, queryParams); //分页带查询参数
    _table.reload();
}

//初始化表格
function loadList() {
    _table.init({
        elem: '#table',
        url: 'Notice.ashx',
        contentType: "application/x-www-form-urlencoded", /**支持跨域**/
        pageSize: 15, //单页记录数
        striped: false, //是否显示行间隔色
        checkboxHeader: true,
        singleSelect: false,
        onLoadSuccess: function (data) {
        },
        params: {
            PostType: 'list',
            ActionType: 'Notice',
            rmd: Math.random()
        }
    });
}

//格式化序号
function formatterNum(value, row, index) {
    //获取每页显示的数量
    var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
    //获取当前是第几页
    var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
    //返回序号，注意index是从0开始的，所以要加上1
    return (pageSize * (pageNumber - 1) + index + 1);
}

//格式化通知类型
function formatterNoticeType(value, row, index) {
    if (value == 0) {
        return '全部';
    } else {
        return '未知';
    }
}

//格式化显示状态
function formatterStatus(value, row, index) {
    if (value == 0) {
        return '<span class="successOutSpan">发布</span>';
    } else {
        return '<span class="dangerOutSpan">屏蔽</span>';
    }
}

//格式化弹窗提示
function formatterIsTip(value, row, index) {
    if (value == 1) {
        return '提示';
    } else {
        return '不提示';
    }
}

//格式化操作按钮
function formatterOperationMenu(value, row, index) {
    return app.getOperationMenu('GUID', row);
}

//新增
function add() {
    layer.open({
        title: "通知信息",
        type: 2,
        area: ["100%", "100%"],
        scrollbar: false,
        content: "NoticeSet.aspx"
    });
}

//查看
function view(id) {
    layer.open({
        title: "通知信息",
        type: 2,
        area: ["100%", "100%"],
        scrollbar: false,
        content: "NoticeView.aspx?GUID=" + id
    });
}

//编辑
function edit(id) {
    layer.open({
        title: "通知信息",
        type: 2,
        area: ["100%", "100%"],
        scrollbar: false,
        content: "NoticeSet.aspx?GUID=" + id
    });
}

//删除
function del(id) {
    layer.confirm('确定删除?', {
        icon: 3,
        title: '提示'
    }, function (index) {
        app.del('Notice.ashx', {
            ActionType: 'Notice',
            GUID: id
        }, function (data) {
            layer.msg(data.msg);
            if (data.success) {
                search();
            }
        });
        layer.close(index);
    });
}
